package com.sc.contact.create;

import org.json.JSONObject;

public class Entry {

	//	{"entry": {
	//		   "id": "urn:lsid:lconn.ibm.com:profiles.person:21843381",
	//		   "appData": {"connections": {
	//		      "organizationId": "urn:lsid:lconn.ibm.com:connections.organization:21842106",
	//		      "isExternal": "false"
	//		   }},
	//		   "emails": [{
	//		      "primary": true,
	//		      "value": "xxx@xxx.com",
	//		      "type": "primary"
	//		   }],
	//		   "displayName": "Xxx Xxx"
	//		}}
	private JSONObject json;

	public Entry(String s) {
		json = new JSONObject(s);
	}

	public String getId() {
		String id = json.getJSONObject("entry").getString("id");
		id = id.substring(id.lastIndexOf(':')+1)+"1";// not sure why we need a 1 added here
		return id;
	}
	
	public String getOrgId() {
		String id = json.getJSONObject("entry").getJSONObject("appData").getJSONObject("connections").getString("organizationId");
		id = id.substring(id.lastIndexOf(':')+1);// not sure why we need a 1 added here
		return id;
	}

	public String getDisplayName() {
		return json.getJSONObject("entry").getString("displayName");
	}

	public String getEmail() {
		return json.getJSONObject("entry").getJSONArray("emails").getJSONObject(0).getString("value");
	}

}
